#Boa:Frame:Frame1
#coding=utf-8
import wx
from twisted.internet import reactor
from protocol.smgp13 import *
from log import log
import sys

def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1BTNACTIVETEST, wxID_FRAME1BTNCLEAR1, 
 wxID_FRAME1BTNCLEAR2, wxID_FRAME1BTNCLEAR3, wxID_FRAME1BTNCLOSE, 
 wxID_FRAME1BTNCONNECT, wxID_FRAME1BTNDELIVER, wxID_FRAME1BTNLISTENER, 
 wxID_FRAME1BTNLOGIN, wxID_FRAME1BTNSENDEXIT, wxID_FRAME1BTNSTOPLISTENER, 
 wxID_FRAME1BTNSTOPSEND_D, wxID_FRAME1BTNSTOPSUBMIT, wxID_FRAME1BTNSUBMIT, 
 wxID_FRAME1CHKAUTOPLUS, wxID_FRAME1CHKSENDREPORT, wxID_FRAME1CHLOGINMODE, 
 wxID_FRAME1CHVERSION, wxID_FRAME1LBPACKET, wxID_FRAME1PANEL1, 
 wxID_FRAME1PANEL2, wxID_FRAME1PANEL3, wxID_FRAME1SPLITTERWINDOW1, 
 wxID_FRAME1STATICTEXT1, wxID_FRAME1STATICTEXT10, wxID_FRAME1STATICTEXT11, 
 wxID_FRAME1STATICTEXT12, wxID_FRAME1STATICTEXT13, wxID_FRAME1STATICTEXT14, 
 wxID_FRAME1STATICTEXT15, wxID_FRAME1STATICTEXT16, wxID_FRAME1STATICTEXT17, 
 wxID_FRAME1STATICTEXT18, wxID_FRAME1STATICTEXT19, wxID_FRAME1STATICTEXT2, 
 wxID_FRAME1STATICTEXT20, wxID_FRAME1STATICTEXT21, wxID_FRAME1STATICTEXT22, 
 wxID_FRAME1STATICTEXT23, wxID_FRAME1STATICTEXT24, wxID_FRAME1STATICTEXT25, 
 wxID_FRAME1STATICTEXT26, wxID_FRAME1STATICTEXT27, wxID_FRAME1STATICTEXT28, 
 wxID_FRAME1STATICTEXT29, wxID_FRAME1STATICTEXT3, wxID_FRAME1STATICTEXT30, 
 wxID_FRAME1STATICTEXT31, wxID_FRAME1STATICTEXT32, wxID_FRAME1STATICTEXT33, 
 wxID_FRAME1STATICTEXT34, wxID_FRAME1STATICTEXT35, wxID_FRAME1STATICTEXT36, 
 wxID_FRAME1STATICTEXT37, wxID_FRAME1STATICTEXT38, wxID_FRAME1STATICTEXT4, 
 wxID_FRAME1STATICTEXT5, wxID_FRAME1STATICTEXT6, wxID_FRAME1STATICTEXT7, 
 wxID_FRAME1STATICTEXT8, wxID_FRAME1STATICTEXT9, wxID_FRAME1STXTSTAT, 
 wxID_FRAME1STXTSTATUS, wxID_FRAME1TXTATTIME, wxID_FRAME1TXTCHARGETERMID, 
 wxID_FRAME1TXTCLIENTID, wxID_FRAME1TXTDESTTERMID, wxID_FRAME1TXTDESTTERMID_D, 
 wxID_FRAME1TXTFEECODE, wxID_FRAME1TXTFEETYPE, wxID_FRAME1TXTHOST, 
 wxID_FRAME1TXTISREPORT, wxID_FRAME1TXTLISTENPORT, wxID_FRAME1TXTLOCALIP, 
 wxID_FRAME1TXTLOG, wxID_FRAME1TXTMSGCONTENT, wxID_FRAME1TXTMSGCONTENT_D, 
 wxID_FRAME1TXTMSGFORMAT, wxID_FRAME1TXTMSGFORMAT_D, wxID_FRAME1TXTMSGID, 
 wxID_FRAME1TXTMSGLENGTH_D, wxID_FRAME1TXTNEEDREPORT, wxID_FRAME1TXTPACKET, 
 wxID_FRAME1TXTPASSWORD, wxID_FRAME1TXTPORT, wxID_FRAME1TXTPRIORITY, 
 wxID_FRAME1TXTRECVTIME, wxID_FRAME1TXTREPORTSTR, wxID_FRAME1TXTRESERVE, 
 wxID_FRAME1TXTRESERVE_D, wxID_FRAME1TXTSENDCOUNT, wxID_FRAME1TXTSENDCOUNT_D, 
 wxID_FRAME1TXTSERVICEID, wxID_FRAME1TXTSRCTERMID, wxID_FRAME1TXTSRCTERMID_D, 
 wxID_FRAME1TXTSUBTYPE, wxID_FRAME1TXTTIMESEP, wxID_FRAME1TXTVALIDTIME, 
] = [wx.NewId() for _init_ctrls in range(99)]

class Frame1(wx.Frame):
    def _init_coll_gridBagSizer3_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.staticText27, (0, 0), border=0, flag=0, span=(1,
              1))
        parent.AddWindow(self.txtMsgID, (0, 1), border=0, flag=0, span=(1, 1))
        parent.AddWindow(self.staticText29, (0, 2), border=0, flag=0, span=(1,
              1))
        parent.AddWindow(self.txtIsReport, (0, 3), border=0, flag=0, span=(1,1))
        parent.AddWindow(self.staticText28, (1, 0), border=0, flag=0, span=(1,
              1))
        parent.AddWindow(self.txtMsgFormat_D, (1, 1), border=0, flag=0, span=(1,
              1))
        parent.AddWindow(self.staticText30, (1, 2), border=0, flag=0, span=(1,
              1))
        parent.AddWindow(self.txtRecvTime, (1, 3), border=0, flag=0, span=(1,1))
        parent.AddWindow(self.staticText31, (2, 0), border=0, flag=0, span=(1,
              1))
        parent.AddWindow(self.txtSrcTermID_D, (2, 1), border=0, flag=0, span=(1,
              1))
        parent.AddWindow(self.staticText32, (2, 2), border=0, flag=0, span=(1,
              1))
        parent.AddWindow(self.txtDestTermID_D, (2, 3), border=0, flag=0,
              span=(1, 1))
        parent.AddWindow(self.staticText33, (3, 0), border=0, flag=0, span=(1,
              1))
        parent.AddWindow(self.txtMsgLength_D, (3, 1), border=0, flag=0, span=(1,
              1))
        parent.AddWindow(self.staticText34, (3, 2), border=0, flag=0, span=(1,
              1))
        parent.AddWindow(self.txtMsgContent_D, (3, 3), border=0, flag=0,
              span=(1, 3))
        parent.AddWindow(self.staticText35, (4, 0), border=0, flag=0, span=(1,
              1))
        parent.AddWindow(self.txtReserve_D, (4, 1), border=0, flag=0, span=(1,
              1))
        parent.AddWindow(self.btnDeliver, (4, 2), border=0, flag=0, span=(1, 1))
        parent.AddWindow(self.btnStopSend_D, (4, 3), border=0, flag=0, span=(1,
              1))
        parent.AddWindow(self.staticText36, (4,4), border=0, flag=0, span=(1,1))
        parent.AddWindow(self.txtSendCount_D, (4, 5), border=0, flag=0, span=(1,
              1))
        parent.AddWindow(self.staticText38, (5, 1), border=0, flag=0, span=(1,
              4))
        parent.AddWindow(self.txtReportStr, (6, 0), border=0, flag=0, span=(1,
              1))
        parent.AddWindow(self.chkSendReport, (5, 0), border=0, flag=0, span=(1,
              1))

    def _init_coll_boxSizer9_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.staticText2, 0, border=0, flag=0)
        parent.AddWindow(self.btnClear2, 0, border=0, flag=0)

    def _init_coll_gridBagSizer2_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.btnActiveTest, (0, 0), border=0, flag=0, span=(1,
              1))

    def _init_coll_flexGridSizer1_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.staticText6, 0, border=0, flag=0)
        parent.AddWindow(self.txtSubType, 0, border=0, flag=0)
        parent.AddWindow(self.staticText9, 0, border=0, flag=0)
        parent.AddWindow(self.txtNeedReport, 0, border=0, flag=0)
        parent.AddWindow(self.staticText10, 0, border=0, flag=0)
        parent.AddWindow(self.txtPriority, 0, border=0, flag=0)
        parent.AddWindow(self.staticText14, 0, border=0, flag=0)
        parent.AddWindow(self.txtServiceID, 0, border=0, flag=0)
        parent.AddWindow(self.staticText12, 0, border=0, flag=0)
        parent.AddWindow(self.txtFeeType, 0, border=0, flag=0)
        parent.AddWindow(self.staticText13, 0, border=0, flag=0)
        parent.AddWindow(self.txtFeeCode, 0, border=0, flag=0)
        parent.AddWindow(self.staticText11, 0, border=0, flag=0)
        parent.AddWindow(self.txtMsgFormat, 0, border=0, flag=0)
        parent.AddWindow(self.staticText15, 0, border=0, flag=0)
        parent.AddWindow(self.txtValidTime, 0, border=0, flag=0)
        parent.AddWindow(self.staticText16, 0, border=0, flag=0)
        parent.AddWindow(self.txtAtTime, 0, border=0, flag=0)
        parent.AddWindow(self.staticText17, 0, border=0, flag=0)
        parent.AddWindow(self.txtSrcTermID, 0, border=0, flag=0)
        parent.AddWindow(self.staticText18, 0, border=0, flag=0)
        parent.AddWindow(self.txtChargeTermID, 0, border=0, flag=0)
        parent.AddWindow(self.staticText19, 0, border=0, flag=0)
        parent.AddWindow(self.txtDestTermID, 0, border=0, flag=0)
        parent.AddWindow(self.staticText20, 0, border=0, flag=0)
        parent.AddWindow(self.txtMsgContent, 0, border=0, flag=0)
        parent.AddWindow(self.staticText21, 0, border=0, flag=0)
        parent.AddWindow(self.txtReserve, 0, border=0, flag=0)
        parent.AddWindow(self.btnSubmit, 0, border=0, flag=0)
        parent.AddWindow(self.btnStopSubmit, 0, border=0, flag=0)
        parent.AddSpacer(wx.Size(8, 8), border=0, flag=0)
        parent.AddWindow(self.chkAutoPlus, 0, border=0, flag=0)
        parent.AddWindow(self.staticText22, 0, border=0, flag=0)
        parent.AddWindow(self.txtSendCount, 0, border=0, flag=0)
        parent.AddWindow(self.staticText23, 0, border=0, flag=0)
        parent.AddWindow(self.txtTimeSep, 0, border=0, flag=0)

    def _init_coll_boxSizer6_Items(self, parent):
        # generated method, don't edit

        parent.AddSizer(self.boxSizer10, 0, border=0, flag=wx.EXPAND)
        parent.AddWindow(self.txtLog, 1, border=0, flag=wx.EXPAND)

    def _init_coll_gridBagSizer1_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.staticText4, (1, 0), border=0, flag=0, span=(1,1))
        parent.AddWindow(self.txtClientID, (1, 1), border=0, flag=0, span=(1,1))
        parent.AddWindow(self.staticText5, (1, 2), border=0, flag=0, span=(1,1))
        parent.AddWindow(self.txtPassword, (1, 3), border=0, flag=0, span=(1,1))
        parent.AddWindow(self.staticText37, (0, 0), border=0, flag=0, span=(1,
              1))
        parent.AddWindow(self.txtListenPort, (0, 1), border=0, flag=0, span=(1,
              1))
        parent.AddWindow(self.btnListener, (0, 2), border=0, flag=0, span=(1,1))
        parent.AddWindow(self.btnStopListener, (0, 3), border=0, flag=0,
              span=(1, 1))
        parent.AddWindow(self.stxtStatus, (0,4), border=0, flag=0, span=(1, 1))
        parent.AddWindow(self.staticText7, (2,0), border=0, flag=0, span=(1, 1))
        parent.AddWindow(self.staticText8, (2, 2), border=0, flag=0, span=(1,1))
        parent.AddWindow(self.chLoginMode, (2, 1), border=0, flag=0, span=(1,1))
        parent.AddWindow(self.chVersion, (2, 3), border=0, flag=0, span=(1, 1))
        parent.AddWindow(self.btnLogin, (3, 0), border=0, flag=0, span=(1, 2))

    def _init_coll_boxSizer4_Items(self, parent):
        # generated method, don't edit

        parent.AddSizer(self.boxSizer8, 0, border=0, flag=wx.EXPAND)
        parent.AddWindow(self.lbPacket, 1, border=0, flag=wx.EXPAND)

    def _init_coll_boxSizer7_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.staticText24, 0, border=0, flag=0)
        parent.AddWindow(self.txtHost, 0, border=0, flag=0)
        parent.AddWindow(self.staticText25, 0, border=0, flag=0)
        parent.AddWindow(self.txtPort, 0, border=0, flag=0)
        parent.AddWindow(self.staticText26, 0, border=0, flag=0)
        parent.AddWindow(self.txtLocalIP, 0, border=0, flag=0)
        parent.AddWindow(self.btnConnect, 0, border=0, flag=0)

    def _init_coll_boxSizer10_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.staticText3, 0, border=0, flag=0)
        parent.AddWindow(self.btnClear3, 0, border=0, flag=0)

    def _init_coll_boxSizer8_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.staticText1, 0, border=0, flag=0)
        parent.AddWindow(self.btnClear1, 0, border=0, flag=0)

    def _init_coll_boxSizer5_Items(self, parent):
        # generated method, don't edit

        parent.AddSizer(self.boxSizer9, 0, border=0, flag=wx.EXPAND)
        parent.AddWindow(self.txtPacket, 1, border=0, flag=wx.EXPAND)

    def _init_coll_boxSizer3_Items(self, parent):
        # generated method, don't edit

        parent.AddSizer(self.boxSizer4, 1, border=0, flag=wx.EXPAND)
        parent.AddSizer(self.boxSizer5, 1, border=0, flag=wx.EXPAND)
        parent.AddSizer(self.boxSizer6, 1, border=0, flag=wx.EXPAND)

    def _init_coll_boxSizer1_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.splitterWindow1, 1, border=0, flag=wx.EXPAND)

    def _init_coll_boxSizer2_Items(self, parent):
        # generated method, don't edit

        parent.AddSizer(self.boxSizer7, 0, border=0, flag=0)
        parent.AddSizer(self.gridBagSizer1, 0, border=0, flag=wx.EXPAND)
        parent.AddSizer(self.gridBagSizer2, 0, border=0, flag=0)
        parent.AddSizer(self.flexGridSizer1, 0, border=0, flag=wx.EXPAND)
        parent.AddWindow(self.btnSendExit, 0, border=0, flag=0)
        parent.AddWindow(self.btnClose, 0, border=0, flag=0)
        parent.AddSizer(self.gridBagSizer3, 0, border=0, flag=wx.EXPAND)
        parent.AddWindow(self.stxtStat, 0, border=0, flag=0)

    def _init_sizers(self):
        # generated method, don't edit
        self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL)

        self.boxSizer2 = wx.BoxSizer(orient=wx.VERTICAL)

        self.boxSizer3 = wx.BoxSizer(orient=wx.VERTICAL)

        self.boxSizer4 = wx.BoxSizer(orient=wx.VERTICAL)

        self.boxSizer5 = wx.BoxSizer(orient=wx.VERTICAL)

        self.boxSizer6 = wx.BoxSizer(orient=wx.VERTICAL)

        self.gridBagSizer1 = wx.GridBagSizer(hgap=0, vgap=0)

        self.gridBagSizer2 = wx.GridBagSizer(hgap=0, vgap=0)

        self.flexGridSizer1 = wx.FlexGridSizer(cols=4, hgap=0, rows=0, vgap=0)

        self.boxSizer7 = wx.BoxSizer(orient=wx.HORIZONTAL)

        self.gridBagSizer3 = wx.GridBagSizer(hgap=0, vgap=0)

        self.boxSizer8 = wx.BoxSizer(orient=wx.HORIZONTAL)

        self.boxSizer9 = wx.BoxSizer(orient=wx.HORIZONTAL)

        self.boxSizer10 = wx.BoxSizer(orient=wx.HORIZONTAL)

        self._init_coll_boxSizer1_Items(self.boxSizer1)
        self._init_coll_boxSizer2_Items(self.boxSizer2)
        self._init_coll_boxSizer3_Items(self.boxSizer3)
        self._init_coll_boxSizer4_Items(self.boxSizer4)
        self._init_coll_boxSizer5_Items(self.boxSizer5)
        self._init_coll_boxSizer6_Items(self.boxSizer6)
        self._init_coll_gridBagSizer1_Items(self.gridBagSizer1)
        self._init_coll_gridBagSizer2_Items(self.gridBagSizer2)
        self._init_coll_flexGridSizer1_Items(self.flexGridSizer1)
        self._init_coll_boxSizer7_Items(self.boxSizer7)
        self._init_coll_gridBagSizer3_Items(self.gridBagSizer3)
        self._init_coll_boxSizer8_Items(self.boxSizer8)
        self._init_coll_boxSizer9_Items(self.boxSizer9)
        self._init_coll_boxSizer10_Items(self.boxSizer10)

        self.panel1.SetSizer(self.boxSizer1)
        self.panel2.SetSizer(self.boxSizer2)
        self.panel3.SetSizer(self.boxSizer3)

    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(285, -8), size=wx.Size(986, 723),
              style=wx.DEFAULT_FRAME_STYLE, title=_(u'Smgp Client'))
        self.SetClientSize(wx.Size(978, 696))
        self.Bind(wx.EVT_CLOSE, self.OnFrame1Close)

        self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
              pos=wx.Point(0, 0), size=wx.Size(978, 696),
              style=wx.TAB_TRAVERSAL)

        self.splitterWindow1 = wx.SplitterWindow(id=wxID_FRAME1SPLITTERWINDOW1,
              name='splitterWindow1', parent=self.panel1, pos=wx.Point(0, 0),
              size=wx.Size(978, 696), style=wx.SP_3D)

        self.panel2 = wx.Panel(id=wxID_FRAME1PANEL2, name='panel2',
              parent=self.splitterWindow1, pos=wx.Point(2, 2), size=wx.Size(575,
              692), style=wx.TAB_TRAVERSAL)

        self.panel3 = wx.Panel(id=wxID_FRAME1PANEL3, name='panel3',
              parent=self.splitterWindow1, pos=wx.Point(584, 2),
              size=wx.Size(392, 692), style=wx.TAB_TRAVERSAL)
        self.splitterWindow1.SplitVertically(self.panel2, self.panel3, 500)

        self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1,
              label=_(u'Packet List:'), name='staticText1', parent=self.panel3,
              pos=wx.Point(0, 0), size=wx.Size(62, 14), style=0)

        self.lbPacket = wx.ListBox(choices=[], id=wxID_FRAME1LBPACKET,
              name=u'lbPacket', parent=self.panel3, pos=wx.Point(0, 24),
              size=wx.Size(392, 206), style=0)
        self.lbPacket.Bind(wx.EVT_LISTBOX, self.OnLbPacketListbox,
              id=wxID_FRAME1LBPACKET)

        self.staticText2 = wx.StaticText(id=wxID_FRAME1STATICTEXT2,
              label=_(u'Packet Details:'), name='staticText2',
              parent=self.panel3, pos=wx.Point(0, 230), size=wx.Size(62, 14),
              style=0)

        self.txtPacket = wx.TextCtrl(id=wxID_FRAME1TXTPACKET, name=u'txtPacket',
              parent=self.panel3, pos=wx.Point(0, 254), size=wx.Size(392, 207),
              style=wx.TE_MULTILINE | wx.TE_RICH2, value=u'')

        self.staticText3 = wx.StaticText(id=wxID_FRAME1STATICTEXT3,
              label=_(u'Log:'), name='staticText3', parent=self.panel3,
              pos=wx.Point(0, 461), size=wx.Size(62, 14), style=0)

        self.txtLog = wx.TextCtrl(id=wxID_FRAME1TXTLOG, name=u'txtLog',
              parent=self.panel3, pos=wx.Point(0, 485), size=wx.Size(392, 207),
              style=wx.TE_MULTILINE | wx.TE_RICH2, value=u'')

        self.staticText4 = wx.StaticText(id=wxID_FRAME1STATICTEXT4,
              label=_(u'clientID:'), name='staticText4', parent=self.panel2,
              pos=wx.Point(0, 48), size=wx.Size(62, 14), style=0)

        self.txtClientID = wx.TextCtrl(id=wxID_FRAME1TXTCLIENTID,
              name=u'txtClientID', parent=self.panel2, pos=wx.Point(69, 48),
              size=wx.Size(82, 22), style=0, value=u'')

        self.staticText5 = wx.StaticText(id=wxID_FRAME1STATICTEXT5,
              label=_(u'password:'), name='staticText5', parent=self.panel2,
              pos=wx.Point(169, 48), size=wx.Size(62, 14), style=0)

        self.txtPassword = wx.TextCtrl(id=wxID_FRAME1TXTPASSWORD,
              name=u'txtPassword', parent=self.panel2, pos=wx.Point(244, 48),
              size=wx.Size(74, 24), style=0, value=u'')

        self.btnListener = wx.Button(id=wxID_FRAME1BTNLISTENER,
              label=_(u'Listener'), name=u'btnListener', parent=self.panel2,
              pos=wx.Point(169, 24), size=wx.Size(75, 24), style=0)
        self.btnListener.Bind(wx.EVT_BUTTON, self.OnBtnListenerButton,
              id=wxID_FRAME1BTNLISTENER)

        self.btnStopListener = wx.Button(id=wxID_FRAME1BTNSTOPLISTENER,
              label=_(u'Stop Listener'), name=u'btnStopListener',
              parent=self.panel2, pos=wx.Point(244, 24), size=wx.Size(109, 24),
              style=0)
        self.btnStopListener.Bind(wx.EVT_BUTTON, self.OnBtnStopListenerButton,
              id=wxID_FRAME1BTNSTOPLISTENER)

        self.stxtStatus = wx.StaticText(id=wxID_FRAME1STXTSTATUS,
              label=_(u'Not Connect'), name=u'stxtStatus', parent=self.panel2,
              pos=wx.Point(353, 24), size=wx.Size(200, 32), style=0)

        self.btnActiveTest = wx.Button(id=wxID_FRAME1BTNACTIVETEST,
              label=_(u'Send Active Test'), name=u'btnActiveTest',
              parent=self.panel2, pos=wx.Point(0, 118), size=wx.Size(160, 24),
              style=0)
        self.btnActiveTest.Bind(wx.EVT_BUTTON, self.OnBtnActiveTestButton,
              id=wxID_FRAME1BTNACTIVETEST)

        self.staticText7 = wx.StaticText(id=wxID_FRAME1STATICTEXT7,
              label=_(u'LoginMode:'), name='staticText7', parent=self.panel2,
              pos=wx.Point(0, 72), size=wx.Size(62, 14), style=0)

        self.staticText8 = wx.StaticText(id=wxID_FRAME1STATICTEXT8,
              label=_(u'Version:'), name='staticText8', parent=self.panel2,
              pos=wx.Point(169, 72), size=wx.Size(62, 14), style=0)

        self.chLoginMode = wx.Choice(choices=['0', '1', '2'],
              id=wxID_FRAME1CHLOGINMODE, name=u'chLoginMode',
              parent=self.panel2, pos=wx.Point(69, 72), size=wx.Size(85, 22),
              style=0)
        self.chLoginMode.SetSelection(2)

        self.chVersion = wx.Choice(choices=['19', '32', '48'],
              id=wxID_FRAME1CHVERSION, name=u'chVersion', parent=self.panel2,
              pos=wx.Point(244, 72), size=wx.Size(74, 22), style=0)
        self.chVersion.SetSelection(0)

        self.staticText6 = wx.StaticText(id=wxID_FRAME1STATICTEXT6,
              label=_(u'subType:'), name='staticText6', parent=self.panel2,
              pos=wx.Point(0, 142), size=wx.Size(62, 14), style=0)

        self.txtSubType = wx.TextCtrl(id=wxID_FRAME1TXTSUBTYPE,
              name=u'txtSubType', parent=self.panel2, pos=wx.Point(96, 142),
              size=wx.Size(100, 22), style=0, value=u'6')

        self.staticText9 = wx.StaticText(id=wxID_FRAME1STATICTEXT9,
              label=_(u'needReport:'), name='staticText9', parent=self.panel2,
              pos=wx.Point(264, 142), size=wx.Size(62, 14), style=0)

        self.txtNeedReport = wx.TextCtrl(id=wxID_FRAME1TXTNEEDREPORT,
              name=u'txtNeedReport', parent=self.panel2, pos=wx.Point(352, 142),
              size=wx.Size(100, 22), style=0, value=u'1')

        self.staticText10 = wx.StaticText(id=wxID_FRAME1STATICTEXT10,
              label=_(u'priority:'), name='staticText10', parent=self.panel2,
              pos=wx.Point(0, 164), size=wx.Size(69, 14), style=0)

        self.txtPriority = wx.TextCtrl(id=wxID_FRAME1TXTPRIORITY,
              name=u'txtPriority', parent=self.panel2, pos=wx.Point(96, 164),
              size=wx.Size(100, 22), style=0, value=u'1')

        self.staticText11 = wx.StaticText(id=wxID_FRAME1STATICTEXT11,
              label=_(u'msgFormat:'), name='staticText11', parent=self.panel2,
              pos=wx.Point(0, 208), size=wx.Size(69, 14), style=0)

        self.txtServiceID = wx.TextCtrl(id=wxID_FRAME1TXTSERVICEID,
              name=u'txtServiceID', parent=self.panel2, pos=wx.Point(352, 164),
              size=wx.Size(100, 22), style=0, value=u'HELP')

        self.staticText12 = wx.StaticText(id=wxID_FRAME1STATICTEXT12,
              label=_(u'feeType:'), name='staticText12', parent=self.panel2,
              pos=wx.Point(0, 186), size=wx.Size(69, 14), style=0)

        self.txtFeeType = wx.TextCtrl(id=wxID_FRAME1TXTFEETYPE,
              name=u'txtFeeType', parent=self.panel2, pos=wx.Point(96, 186),
              size=wx.Size(100, 22), style=0, value=u'00')

        self.staticText13 = wx.StaticText(id=wxID_FRAME1STATICTEXT13,
              label=_(u'feeCode:'), name='staticText13', parent=self.panel2,
              pos=wx.Point(264, 186), size=wx.Size(69, 14), style=0)

        self.txtFeeCode = wx.TextCtrl(id=wxID_FRAME1TXTFEECODE,
              name=u'txtFeeCode', parent=self.panel2, pos=wx.Point(352, 186),
              size=wx.Size(100, 22), style=0, value=u'000000')

        self.staticText14 = wx.StaticText(id=wxID_FRAME1STATICTEXT14,
              label=_(u'serviceID'), name='staticText14', parent=self.panel2,
              pos=wx.Point(264, 164), size=wx.Size(69, 14), style=0)

        self.txtMsgFormat = wx.TextCtrl(id=wxID_FRAME1TXTMSGFORMAT,
              name=u'txtMsgFormat', parent=self.panel2, pos=wx.Point(96, 208),
              size=wx.Size(100, 22), style=0, value=u'15')

        self.staticText15 = wx.StaticText(id=wxID_FRAME1STATICTEXT15,
              label=_(u'validTime'), name='staticText15', parent=self.panel2,
              pos=wx.Point(264, 208), size=wx.Size(69, 14), style=0)

        self.txtValidTime = wx.TextCtrl(id=wxID_FRAME1TXTVALIDTIME,
              name=u'txtValidTime', parent=self.panel2, pos=wx.Point(352, 208),
              size=wx.Size(100, 22), style=0, value=u'')

        self.staticText16 = wx.StaticText(id=wxID_FRAME1STATICTEXT16,
              label=_(u'atTime:'), name='staticText16', parent=self.panel2,
              pos=wx.Point(0, 230), size=wx.Size(69, 14), style=0)

        self.txtAtTime = wx.TextCtrl(id=wxID_FRAME1TXTATTIME, name=u'txtAtTime',
              parent=self.panel2, pos=wx.Point(96, 230), size=wx.Size(100, 22),
              style=0, value=u'')

        self.staticText17 = wx.StaticText(id=wxID_FRAME1STATICTEXT17,
              label=_(u'srcTermID:'), name='staticText17', parent=self.panel2,
              pos=wx.Point(264, 230), size=wx.Size(69, 14), style=0)

        self.txtSrcTermID = wx.TextCtrl(id=wxID_FRAME1TXTSRCTERMID,
              name=u'txtSrcTermID', parent=self.panel2, pos=wx.Point(352, 230),
              size=wx.Size(100, 22), style=0, value=u'10659123')

        self.staticText18 = wx.StaticText(id=wxID_FRAME1STATICTEXT18,
              label=_(u'chargeTermID:'), name='staticText18',
              parent=self.panel2, pos=wx.Point(0, 252), size=wx.Size(69, 14),
              style=0)

        self.txtChargeTermID = wx.TextCtrl(id=wxID_FRAME1TXTCHARGETERMID,
              name=u'txtChargeTermID', parent=self.panel2, pos=wx.Point(96,
              252), size=wx.Size(100, 22), style=0, value=u'02112345678')

        self.staticText19 = wx.StaticText(id=wxID_FRAME1STATICTEXT19,
              label=_(u'destTermID:'), name='staticText19', parent=self.panel2,
              pos=wx.Point(264, 252), size=wx.Size(69, 14), style=0)

        self.txtDestTermID = wx.TextCtrl(id=wxID_FRAME1TXTDESTTERMID,
              name=u'txtDestTermID', parent=self.panel2, pos=wx.Point(352, 252),
              size=wx.Size(100, 22), style=0, value=u'02112345678')

        self.staticText20 = wx.StaticText(id=wxID_FRAME1STATICTEXT20,
              label=_(u'msgContent:'), name='staticText20', parent=self.panel2,
              pos=wx.Point(0, 274), size=wx.Size(69, 14), style=0)

        self.txtMsgContent = wx.TextCtrl(id=wxID_FRAME1TXTMSGCONTENT,
              name=u'txtMsgContent', parent=self.panel2, pos=wx.Point(96, 274),
              size=wx.Size(168, 118), style=wx.TE_LINEWRAP | wx.TE_MULTILINE,
              value=u'This is Test sms!')

        self.staticText21 = wx.StaticText(id=wxID_FRAME1STATICTEXT21,
              label=_(u'reserve:'), name='staticText21', parent=self.panel2,
              pos=wx.Point(264, 274), size=wx.Size(69, 14), style=0)

        self.txtReserve = wx.TextCtrl(id=wxID_FRAME1TXTRESERVE,
              name=u'txtReserve', parent=self.panel2, pos=wx.Point(352, 274),
              size=wx.Size(100, 22), style=0, value=u'')

        self.btnSubmit = wx.Button(id=wxID_FRAME1BTNSUBMIT,
              label=_(u'Send Submit'), name=u'btnSubmit', parent=self.panel2,
              pos=wx.Point(0, 392), size=wx.Size(96, 24), style=0)
        self.btnSubmit.Bind(wx.EVT_BUTTON, self.OnBtnSubmitButton,
              id=wxID_FRAME1BTNSUBMIT)

        self.chkAutoPlus = wx.CheckBox(id=wxID_FRAME1CHKAUTOPLUS,
              label=_(u'destTermId Auto Plus'), name=u'chkAutoPlus',
              parent=self.panel2, pos=wx.Point(352, 392), size=wx.Size(154, 14),
              style=0)
        self.chkAutoPlus.SetValue(True)

        self.btnStopSubmit = wx.Button(id=wxID_FRAME1BTNSTOPSUBMIT,
              label=_(u'Stop Send'), name=u'btnStopSubmit', parent=self.panel2,
              pos=wx.Point(96, 392), size=wx.Size(88, 24), style=0)
        self.btnStopSubmit.Bind(wx.EVT_BUTTON, self.OnBtnStopSubmitButton,
              id=wxID_FRAME1BTNSTOPSUBMIT)

        self.btnSendExit = wx.Button(id=wxID_FRAME1BTNSENDEXIT,
              label=_(u'Send Exit'), name=u'btnSendExit', parent=self.panel2,
              pos=wx.Point(0, 438), size=wx.Size(184, 24), style=0)
        self.btnSendExit.Bind(wx.EVT_BUTTON, self.OnBtnSendExitButton,
              id=wxID_FRAME1BTNSENDEXIT)

        self.staticText22 = wx.StaticText(id=wxID_FRAME1STATICTEXT22,
              label=_(u'Send Count:'), name='staticText22', parent=self.panel2,
              pos=wx.Point(0, 416), size=wx.Size(69, 14), style=0)

        self.txtSendCount = wx.TextCtrl(id=wxID_FRAME1TXTSENDCOUNT,
              name=u'txtSendCount', parent=self.panel2, pos=wx.Point(96, 416),
              size=wx.Size(100, 22), style=0, value=u'1')

        self.staticText23 = wx.StaticText(id=wxID_FRAME1STATICTEXT23,
              label=_(u'Send Time Seq:'), name='staticText23',
              parent=self.panel2, pos=wx.Point(264, 416), size=wx.Size(88, 14),
              style=0)

        self.txtTimeSep = wx.TextCtrl(id=wxID_FRAME1TXTTIMESEP,
              name=u'txtTimeSep', parent=self.panel2, pos=wx.Point(352, 416),
              size=wx.Size(100, 22), style=0, value=u'1000')

        self.btnClose = wx.Button(id=wxID_FRAME1BTNCLOSE, label=_(u'Close'),
              name=u'btnClose', parent=self.panel2, pos=wx.Point(0, 462),
              size=wx.Size(75, 24), style=0)
        self.btnClose.Bind(wx.EVT_BUTTON, self.OnBtnCloseButton,
              id=wxID_FRAME1BTNCLOSE)

        self.staticText24 = wx.StaticText(id=wxID_FRAME1STATICTEXT24,
              label=_(u'host:'), name='staticText24', parent=self.panel2,
              pos=wx.Point(0, 0), size=wx.Size(40, 14), style=0)

        self.txtHost = wx.TextCtrl(id=wxID_FRAME1TXTHOST, name=u'txtHost',
              parent=self.panel2, pos=wx.Point(40, 0), size=wx.Size(88, 22),
              style=0, value=u'127.0.0.1')

        self.staticText25 = wx.StaticText(id=wxID_FRAME1STATICTEXT25,
              label=_(u'port:'), name='staticText25', parent=self.panel2,
              pos=wx.Point(128, 0), size=wx.Size(36, 14), style=0)

        self.txtPort = wx.TextCtrl(id=wxID_FRAME1TXTPORT, name=u'txtPort',
              parent=self.panel2, pos=wx.Point(164, 0), size=wx.Size(52, 22),
              style=0, value=u'8890')

        self.staticText26 = wx.StaticText(id=wxID_FRAME1STATICTEXT26,
              label=_(u'local ip:'), name='staticText26', parent=self.panel2,
              pos=wx.Point(216, 0), size=wx.Size(44, 14), style=0)

        self.txtLocalIP = wx.TextCtrl(id=wxID_FRAME1TXTLOCALIP,
              name=u'txtLocalIP', parent=self.panel2, pos=wx.Point(260, 0),
              size=wx.Size(100, 22), style=0, value=u'')

        self.btnLogin = wx.Button(id=wxID_FRAME1BTNLOGIN,
              label=_(u'send Login'), name=u'btnLogin', parent=self.panel2,
              pos=wx.Point(0, 94), size=wx.Size(160, 24), style=0)
        self.btnLogin.Bind(wx.EVT_BUTTON, self.OnBtnLoginButton,
              id=wxID_FRAME1BTNLOGIN)

        self.staticText27 = wx.StaticText(id=wxID_FRAME1STATICTEXT27,
              label=_(u'msgID'), name='staticText27', parent=self.panel2,
              pos=wx.Point(0, 486), size=wx.Size(69, 14), style=0)

        self.txtIsReport = wx.TextCtrl(id=wxID_FRAME1TXTISREPORT,
              name=u'txtIsReport', parent=self.panel2, pos=wx.Point(287, 486),
              size=wx.Size(100, 22), style=0, value=u'1')

        self.staticText28 = wx.StaticText(id=wxID_FRAME1STATICTEXT28,
              label=_(u'msgFormat'), name='staticText28', parent=self.panel2,
              pos=wx.Point(0, 508), size=wx.Size(69, 14), style=0)

        self.txtMsgID = wx.TextCtrl(id=wxID_FRAME1TXTMSGID, name=u'txtMsgID',
              parent=self.panel2, pos=wx.Point(100, 486), size=wx.Size(100, 22),
              style=wx.TE_READONLY, value=u'Auto Gen')

        self.staticText29 = wx.StaticText(id=wxID_FRAME1STATICTEXT29,
              label=_(u'isReport'), name='staticText29', parent=self.panel2,
              pos=wx.Point(200, 486), size=wx.Size(69, 14), style=0)

        self.txtMsgFormat_D = wx.TextCtrl(id=wxID_FRAME1TXTMSGFORMAT_D,
              name=u'txtMsgFormat_D', parent=self.panel2, pos=wx.Point(100,
              508), size=wx.Size(100, 22), style=0, value=u'15')

        self.staticText30 = wx.StaticText(id=wxID_FRAME1STATICTEXT30,
              label=u'recvTime', name='staticText30', parent=self.panel2,
              pos=wx.Point(200, 508), size=wx.Size(69, 14), style=0)

        self.txtRecvTime = wx.TextCtrl(id=wxID_FRAME1TXTRECVTIME,
              name=u'txtRecvTime', parent=self.panel2, pos=wx.Point(287, 508),
              size=wx.Size(100, 22), style=0, value=u'')

        self.staticText31 = wx.StaticText(id=wxID_FRAME1STATICTEXT31,
              label=_(u'srcTermID'), name='staticText31', parent=self.panel2,
              pos=wx.Point(0, 530), size=wx.Size(69, 14), style=0)

        self.txtSrcTermID_D = wx.TextCtrl(id=wxID_FRAME1TXTSRCTERMID_D,
              name=u'txtSrcTermID_D', parent=self.panel2, pos=wx.Point(100,
              530), size=wx.Size(100, 22), style=0, value=u'02112341234')

        self.staticText32 = wx.StaticText(id=wxID_FRAME1STATICTEXT32,
              label=u'destTermID', name='staticText32', parent=self.panel2,
              pos=wx.Point(200, 530), size=wx.Size(69, 14), style=0)

        self.txtDestTermID_D = wx.TextCtrl(id=wxID_FRAME1TXTDESTTERMID_D,
              name=u'txtDestTermID_D', parent=self.panel2, pos=wx.Point(287,
              530), size=wx.Size(100, 22), style=0, value=u'10659123')

        self.staticText33 = wx.StaticText(id=wxID_FRAME1STATICTEXT33,
              label=u'msgLength', name='staticText33', parent=self.panel2,
              pos=wx.Point(0, 552), size=wx.Size(69, 14), style=0)

        self.staticText34 = wx.StaticText(id=wxID_FRAME1STATICTEXT34,
              label=_(u'msgContent'), name='staticText34', parent=self.panel2,
              pos=wx.Point(200, 552), size=wx.Size(69, 14), style=0)

        self.txtMsgLength_D = wx.TextCtrl(id=wxID_FRAME1TXTMSGLENGTH_D,
              name=u'txtMsgLength_D', parent=self.panel2, pos=wx.Point(100,
              552), size=wx.Size(100, 22), style=wx.TE_READONLY,
              value=u'Auto Gen')

        self.txtMsgContent_D = wx.TextCtrl(id=wxID_FRAME1TXTMSGCONTENT_D,
              name=u'txtMsgContent_D', parent=self.panel2, pos=wx.Point(287,
              552), size=wx.Size(202, 74), style=wx.TE_MULTILINE,
              value=u'This is Deliver test sms!')

        self.staticText35 = wx.StaticText(id=wxID_FRAME1STATICTEXT35,
              label=_(u'reserve'), name='staticText35', parent=self.panel2,
              pos=wx.Point(0, 626), size=wx.Size(69, 14), style=0)

        self.txtReserve_D = wx.TextCtrl(id=wxID_FRAME1TXTRESERVE_D,
              name=u'txtReserve_D', parent=self.panel2, pos=wx.Point(100, 626),
              size=wx.Size(100, 22), style=0, value=u'')

        self.btnDeliver = wx.Button(id=wxID_FRAME1BTNDELIVER,
              label=_(u'Send Deliver'), name=u'btnDeliver', parent=self.panel2,
              pos=wx.Point(200, 626), size=wx.Size(87, 24), style=0)
        self.btnDeliver.Bind(wx.EVT_BUTTON, self.OnBtnDeliverButton,
              id=wxID_FRAME1BTNDELIVER)

        self.staticText36 = wx.StaticText(id=wxID_FRAME1STATICTEXT36,
              label=_(u'Send Count:'), name='staticText36', parent=self.panel2,
              pos=wx.Point(387, 626), size=wx.Size(69, 14), style=0)

        self.txtSendCount_D = wx.TextCtrl(id=wxID_FRAME1TXTSENDCOUNT_D,
              name=u'txtSendCount_D', parent=self.panel2, pos=wx.Point(488,
              626), size=wx.Size(40, 22), style=0, value=u'1')

        self.btnStopSend_D = wx.Button(id=wxID_FRAME1BTNSTOPSEND_D,
              label=_(u'Stop Send'), name=u'btnStopSend_D', parent=self.panel2,
              pos=wx.Point(287, 626), size=wx.Size(75, 24), style=0)
        self.btnStopSend_D.Bind(wx.EVT_BUTTON, self.OnBtnStopSend_DButton,
              id=wxID_FRAME1BTNSTOPSEND_D)

        self.btnClear1 = wx.Button(id=wxID_FRAME1BTNCLEAR1, label=u'Clear Text',
              name=u'btnClear1', parent=self.panel3, pos=wx.Point(62, 0),
              size=wx.Size(75, 24), style=0)
        self.btnClear1.Bind(wx.EVT_BUTTON, self.OnBtnClear1Button,
              id=wxID_FRAME1BTNCLEAR1)

        self.btnClear2 = wx.Button(id=wxID_FRAME1BTNCLEAR2,
              label=_(u'Clear Text'), name=u'btnClear2', parent=self.panel3,
              pos=wx.Point(62, 230), size=wx.Size(75, 24), style=0)
        self.btnClear2.Bind(wx.EVT_BUTTON, self.OnBtnClear2Button,
              id=wxID_FRAME1BTNCLEAR2)

        self.btnClear3 = wx.Button(id=wxID_FRAME1BTNCLEAR3, label=u'Clear Text',
              name=u'btnClear3', parent=self.panel3, pos=wx.Point(62, 461),
              size=wx.Size(75, 24), style=0)
        self.btnClear3.Bind(wx.EVT_BUTTON, self.OnBtnClear3Button,
              id=wxID_FRAME1BTNCLEAR3)

        self.stxtStat = wx.StaticText(id=wxID_FRAME1STXTSTAT, label=u'stxtStat',
              name=u'stxtStat', parent=self.panel2, pos=wx.Point(0, 686),
              size=wx.Size(44, 14), style=0)

        self.btnConnect = wx.Button(id=wxID_FRAME1BTNCONNECT,
              label=_(u'Connect'), name=u'btnConnect', parent=self.panel2,
              pos=wx.Point(360, 0), size=wx.Size(75, 24), style=0)
        self.btnConnect.Bind(wx.EVT_BUTTON, self.OnBtnConnectButton,
              id=wxID_FRAME1BTNCONNECT)

        self.staticText37 = wx.StaticText(id=wxID_FRAME1STATICTEXT37,
              label=u'listen port:', name='staticText37', parent=self.panel2,
              pos=wx.Point(0, 24), size=wx.Size(69, 14), style=0)

        self.txtListenPort = wx.TextCtrl(id=wxID_FRAME1TXTLISTENPORT,
              name=u'txtListenPort', parent=self.panel2, pos=wx.Point(69, 24),
              size=wx.Size(100, 22), style=0, value=u'8890')

        self.staticText38 = wx.StaticText(id=wxID_FRAME1STATICTEXT38,
              label=u'\u56de\u590d\u6309\u4e0b\u9762\u683c\u5f0f\u4e32\u56de\u590d\u72b6\u6001\u62a5\u544a,_M_\u7528msgID\u66ff\u6362,_T_\u6709\u5f53\u524d\u65f6\u95f4\u66ff\u6362',
              name='staticText38', parent=self.panel2, pos=wx.Point(100, 650),
              size=wx.Size(388, 14), style=0)

        self.txtReportStr = wx.TextCtrl(id=wxID_FRAME1TXTREPORTSTR,
              name=u'txtReportStr', parent=self.panel2, pos=wx.Point(0, 664),
              size=wx.Size(100, 22), style=0, value=u'')

        self.chkSendReport = wx.CheckBox(id=wxID_FRAME1CHKSENDREPORT,
              label=u'Resp Report', name=u'chkSendReport', parent=self.panel2,
              pos=wx.Point(0, 650), size=wx.Size(79, 14), style=0)
        self.chkSendReport.SetValue(False)

        self._init_sizers()

    def __init__(self, parent):
        self._init_ctrls(parent)
        # make sure reactor.stop() is used to stop event loop:
        self.sp = None
        self.cp = None
        self.p = None
        self.serverFactory = Smgp13ServerFactory()
        self.clientFactory = Smgp13ClientFactory()
        #d = self.factory.getConnectDefer()
        eventMgr.Register(lambda evt: self.txtLog.AppendText('connect to ' + self.txtHost.GetValue()), SMGP13CONNECTING, self.serverFactory)
        eventMgr.Register(self.spBuild, SMGP13PROTOCOLBUILD, self.serverFactory)
        #eventMgr.Register(self.connectFailListener, SMGP13CONNECTFAIL, self.factory)
        
        eventMgr.Register(lambda evt: self.txtLog.AppendText('connect to ' + self.txtHost.GetValue()), SMGP13CONNECTING, self.clientFactory)
        eventMgr.Register(self.cpBuild, SMGP13PROTOCOLBUILD, self.clientFactory)
        #eventMgr.Register(self.connectFailListener, SMGP13CONNECTFAIL, self.factory)
        self.connectFlag = False
        self.autoSendFlag = False
        self.sendFlag = False
        self.sendDeliverFlag = False
        
        self.clientStatus = u'客户端:断连'
        self.serverStatus = u'服务端:未运行'
        self.stxtStatus.SetLabel(self.clientStatus + '\n' + self.serverStatus)
    def spBuild(self, event):
        self.sp = event.data
        log.debug('protocol build')
        
        #连接建立后,注册
        eventMgr.Register(self.spConnectedListener, SMGP13CONNECTED, self.sp)

        
    def cpBuild(self, event):
        self.cp = event.data
        log.debug('protocol build')
        
        #连接建立后,注册
        eventMgr.Register(self.cpConnectedListener, SMGP13CONNECTED, self.cp)

    def spRecvMessageListener(self, event):
        self.txtLog.AppendText(Utils.bin2hexstr(event.data.toStr()) + '\n')
        m = event.data
        s = str(m.sequenceID).ljust(10,' ') + 'SP <= SMC     ' +  Smgp13Util.id2str(m.requestID).ljust(50,' ') + ' length:' + str(m.packetLength)
        self.lbPacket.Append(s, m)
        
    def spSendMessageListener(self, event):
        self.txtLog.AppendText(Utils.bin2hexstr(event.data.toStr()) + '\n')
        m = event.data
        s = str(m.sequenceID).ljust(10,' ') + 'SP => SMC     ' +  Smgp13Util.id2str(m.requestID).ljust(50,' ') + ' length:' + str(m.packetLength)
        log.debug(s)
        self.lbPacket.Append(s, m)
        
    def cpRecvMessageListener(self, event):
        self.txtLog.AppendText(Utils.bin2hexstr(event.data.toStr()) + '\n')
        m = event.data
        s = str(m.sequenceID).ljust(10,' ') + 'SP <= SMC     '  +  Smgp13Util.id2str(m.requestID).ljust(50,' ') + ' length:' + str(m.packetLength)
        self.lbPacket.Append(s, m)
        
    def cpSendMessageListener(self, event):
        self.txtLog.AppendText(Utils.bin2hexstr(event.data.toStr()) + '\n')
        m = event.data
        s = str(m.sequenceID).ljust(10,' ') + 'SP => SMC     ' +  Smgp13Util.id2str(m.requestID).ljust(50,' ') + ' length:' + str(m.packetLength)
        log.debug(s)
        self.lbPacket.Append(s, m)
        
    def spConnectedListener(self, event):
        self.serverStatus = u'服务端:已连接:'
        self.stxtStatus.SetLabel(self.clientStatus + '\n' + self.serverStatus)
        self.txtLog.AppendText('connect success!\n')
        eventMgr.Register(lambda evt:wx.CallAfter(self.spRecvMessageListener, evt), SMGP13RECEIVERED, self.sp.handler)
        eventMgr.Register(lambda evt:wx.CallAfter(self.spSendMessageListener, evt), SMGP13SENDED, self.sp.handler)
        eventMgr.Register(lambda evt:wx.CallAfter(self.spSendMessageListener, evt), SMGP13LOGIN_RECV, self.sp.handler)
        #eventMgr.Register(self.recvMessageListener, SMGP13ACTIVETEST_RECV, self.p.handler)
    def spConnectFailListener(self, event):
        self.serverStatus = u'服务端:连接失败' 
        self.stxtStatus.SetLabel(self.clientStatus + '\n' + self.serverStatus)
        connector, reason = event.data
        log.debug(reason.getErrorMessage())
        self.txtLog.AppendText('connect fail')
        
    def spConnectLostListener(self, event):
        self.serverStatus = u'服务端:连接已断'
        self.stxtStatus.SetLabel(self.clientStatus + '\n' + self.serverStatus)
        self.txtLog.AppendText(str(reason) + '\n')
        
        
    def authConnect(self, event):
        m = event.data
        self.txtLog.AppendText(m.clientID + '\n')
        
    def cpConnectedListener(self, event):
        
        self.clientStatus = u'客户端:已连接:' + self.txtHost.GetValue() + ':' + self.txtPort.GetValue()
        self.stxtStatus.SetLabel(self.clientStatus + '\n' + self.serverStatus)
        self.txtLog.AppendText('connect success!\n')
        eventMgr.Register(lambda evt:wx.CallAfter(self.cpRecvMessageListener, evt), SMGP13RECEIVERED, self.cp.handler)
        eventMgr.Register(lambda evt:wx.CallAfter(self.cpSendMessageListener, evt), SMGP13SENDED, self.cp.handler)
        #eventMgr.Register(self.recvMessageListener, SMGP13ACTIVETEST_RECV, self.p.handler)
    def cpConnectFailListener(self, event):
        self.clientStatus = u'客户端:连接失败:' + self.txtHost.GetValue() + ':' + self.txtPort.GetValue()
        self.stxtStatus.SetLabel(self.clientStatus + '\n' + self.serverStatus)
        connector, reason = event.data
        log.debug(reason.getErrorMessage())
        self.txtLog.AppendText('connect fail')
        
    def cpConnectLostListener(self, event):
        self.clientStatus = u'客户端:连接已断:' + self.txtHost.GetValue() + ':' + self.txtPort.GetValue()
        self.stxtStatus.SetLabel(self.clientStatus + '\n' + self.serverStatus)
        self.txtLog.AppendText(str(reason) + '\n')
        
    def OnBtnConnectButton(self, event):
        if not self.connectFlag:
            try:
                host = self.txtHost.GetValue()
                port = int(self.txtPort.GetValue())
                localip = self.txtLocalIP.GetValue()
                
                if localip == "":
                    bindaddr = None
                else:
                    bindaddr = (localip, 0)
                reactor.connectTCP(host, port, self.clientFactory)#, bindAddress=bindaddr)
            
                self.clientStatus = u'客户端:正在连接:' + host + ':' + str(port)
                self.stxtStatus.SetLabel(self.clientStatus + '\n' + self.serverStatus)
            except:
                self.txtLog.AppendText(str(sys.exc_info()))

    def OnBtnDisconnectButton(self, event):
        event.Skip()

    def OnBtnActiveTestButton(self, event):
        m = Smgp13Util.makeActiveTest()
        if self.cp != None:
            self.cp.handler.submitMessage(m)
        if self.sp != None:
            self.sp.handler.submitMessage(m)

    def OnBtnSubmitButton(self, event):
        try:
            subType = int(self.txtSubType.GetValue())
            needReport = int(self.txtNeedReport.GetValue())
            priority = int(self.txtPriority.GetValue())
            serviceID = str(self.txtServiceID.GetValue())
            feeType = str(self.txtFeeType.GetValue())
            feeCode = str(self.txtFeeCode.GetValue())
            msgFormat = int(self.txtMsgFormat.GetValue())
            validTime = str(self.txtValidTime.GetValue())  #format:YYMMDDhhmmsstnnp
            atTime = str(self.txtAtTime.GetValue())
            srcTermID = str(self.txtSrcTermID.GetValue())
            chargeTermID = str(self.txtChargeTermID.GetValue())
            destTermID = str(self.txtDestTermID.GetValue())  #多个号用逗号分隔
            msgContent = self.txtMsgContent.GetValue()  #直接传入unicode的内容和msgFormat到makeSubmit
            reserve = str(self.txtReserve.GetValue())
            
            #self.autoSendFlag = self.chkAutoSend.GetValue()
            sendcount = int(self.txtSendCount.GetValue())
            self.sendFlag = True
            for i in range(sendcount):
                if not self.sendFlag:
                    break
                m = Smgp13Util.makeSubmit(msgContent, msgFormat)
                m.subType = subType
                m.needReport = needReport
                m.priority = priority
                m.serviceID = serviceID
                m.feeType = feeType
                m.feeCode = feeCode
                m.validTime = validTime
                m.atTime = atTime
                m.srcTermID = srcTermID
                m.chargeTermID = m.chargeTermID
                
                destList = destTermID.split(',')            
                m.destTermID = "".join([s1.ljust(21, '\x00') for s1 in destList])
                m.destTermIDCount = len(destList)
                m.packetLength = len(m.destTermID) + m.msgLength + m.packetLength
                
                
                if self.cp != None:
                    self.cp.handler.submitMessage(m)
                if self.sp != None:
                    self.sp.handler.submitMessage(m)
        except:
            raise
        


    def OnBtnStopSubmitButton(self, event):
        self.sendFlag = False

    def OnBtnSendExitButton(self, event):
        event.Skip()

    def OnLbPacketListbox(self, event):
        m = event.GetClientData()
        self.txtPacket.SetValue(unicode(m) + '\n\n')
        self.txtPacket.AppendText(Utils.m2hex(m) + '\n\n')

    def OnBtnCloseButton(self, event):
        self.Close()

    def OnFrame1Close(self, event):
        reactor.stop()

    def OnBtnLoginButton(self, event):
        if self.cp != None:
            clientID = str(self.txtClientID.GetValue())
            password = str(self.txtPassword.GetValue())
            
            m = Smgp13Util.makeLogin(clientID, password)
            m.loginMode = int(self.chLoginMode.GetStringSelection())
            m.version = int(self.chVersion.GetStringSelection())
            
            self.cp.handler.submitMessage(m)
        
        
    def OnBtnListenerButton(self, event):
        if not self.connectFlag:
            try:
#                host = self.txtHost.GetValue()
                port = int(self.txtListenPort.GetValue())
#                localip = self.txtLocalIP.GetValue()
#                
#                if localip == "":
#                    bindaddr = None
#                else:
#                    bindaddr = (localip, 0)
                reactor.listenTCP(port, self.serverFactory)#, bindAddress=bindaddr)
                self.serverStatus = u'服务器:侦听端口:' + str(port)
                self.stxtStatus.SetLabel(self.clientStatus + '\n' + self.serverStatus)
            except:
                self.txtLog.AppendText(str(sys.exc_info()))


    def OnBtnStopListenerButton(self, event):
        pass

    def OnBtnDeliverButton(self, event):
        try:
            #msgID = self.txtMsgID.GetValue()
            isReport = int(self.txtIsReport.GetValue())
            msgFormat = int(self.txtMsgFormat_D.GetValue())
            recvTime = str(self.txtRecvTime.GetValue())
            srcTermID = str(self.txtSrcTermID_D.GetValue())
            destTermID = str(self.txtDestTermID_D.GetValue())
            msgContent = self.txtMsgContent_D.GetValue()
            reserve = self.txtReserve_D.GetValue().encode('ascii')
            
            sendcount = int(self.txtSendCount_D.GetValue())
            
            self.sendDeliverFlag = True
            for i in range(sendcount):
                if not self.sendDeliverFlag:
                    break
                m = Smgp13Util.makeDeliver(msgContent, msgFormat)
                m.isReport = isReport
                if recvTime == '':
                    m.recvTime = Smgp13Util.genRecvTime()
                else:
                    m.recvTime = recvTime
                m.srcTermID = srcTermID
                m.destTermID = destTermID
                m.reserve = reserve
                m.packetLength += m.msgLength
                
                if self.cp != None:
                    self.cp.handler.submitMessage(m)
                if self.sp != None:
                    self.sp.handler.submitMessage(m)
            
        except:
            raise

    def OnBtnStopSend_DButton(self, event):
        self.sendDeliverFlag = False

    def OnBtnClear1Button(self, event):
        self.lbPacket.Clear()

    def OnBtnClear2Button(self, event):
        self.txtPacket.Clear()

    def OnBtnClear3Button(self, event):
        self.txtLog.Clear()

        
